<div class="container-fluid" style="padding: 20px 10px 0px 10px">
	<p style="color:red;display:none;position:absolute;right:30px;top:25px" id="plusIng">计算中..</p>
    <div class="row-fluid">
        <div class="well">
            <ul class="nav nav-tabs">
                <li class="active"><b>商品管理</b></li>
            </ul>
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane active in" id="home">
                    <form id="formid" action="/bjie/goodsEdit" method="post">
                        <p>商品名称：<input type="text" value="<?=$getData['goods_title']?>" placeholder="商品名称" style="width:570px" name="goods_title" type='text' class="goods_title"></p>
                        <p style="display:inline">商品现价：<input type="text" placeholder="最低售价 <?=$lowPrice?> 元" style="width:126px" name="goods_hb_price" type='text' value="" class="goods_hb_price"> 元 &nbsp;
                            &nbsp;&nbsp;
                            <span style="color: red;">税况</span>：<select style="width: 160px" name="taxes" id="taxesId">
                                <option value="1" <if condition="$getData['taxes'] eq 1">selected</if> >保税仓（完税）</option>
								<option value="2" <if condition="$getData['taxes'] eq 2">selected</if> >保税仓（未完税）</option>
								<option value="3" <if condition="$getData['taxes'] eq 3">selected</if> >大贸（完税）</option>
                                <option value="4" <if condition="$getData['taxes'] eq 4">selected</if> >海外直邮（完税）</option>
                                <option value="5" <if condition="$getData['taxes'] eq 5">selected</if> >海外直邮（未完税）</option>
                            </select>
                            <span style="color: red;">扣税品类</span>：<select style="width: 125px" name="rate" id="plrate">
                            <option value="-1">请选择品类</option>
                            <?php foreach($getRateArr AS $vkk=>$vmm){?>
                            	<option value="<?=$vkk?>"><?=$vmm[0]?></option>
                            <?php }?>
                            </select>
                        </p>
                        </br>
                        <p style="display:inline">销售价格：<input type="text" value="" placeholder="销售价格" style="width:65px" name="goods_price" type='text' class="goods_price"> 元 &nbsp;
                            / &nbsp;&nbsp;<input type="text" value="<?=$getData['goods_attr']?>" placeholder="件/个等" style="width:25px" name="goods_attr" type='text' class="goods_attr">&nbsp;
                             扣税：<input type="text" style="width: 59px;" name="goods_taxes_price" placeholder="扣税金额" class="goods_taxes_price" /> 元
                            <!--成本价格：<input type="text" value="{{$getData.goods_price}}" placeholder="成本价格" style="width:80px" name="channel_price" type='text' class="channel_price" readonly> 元-->
                            <!--&nbsp;盈利预估：<input id="ylz" type="text" style="width: 66px;" disabled value="{{$getData['goods_price']-$getData.channel_price}}" placeholder="盈利预估" name="" class="" /> 元-->
                            参考价格：<input type="text" style="width: 65px;" name="refer_price" placeholder="参考价格" class="refer_price" />
                            &nbsp;品牌：<input type="text" style="width: 60px;" value="<?=$getData['brand']?>" placeholder="品牌名称" disabled />&nbsp;&nbsp;
                        </p>
                        
                        
                        <input type="hidden" value="" name="goods_full_price" id="goods_full_price" />
                        <input type="hidden" value="" name="ratesnum" id="rates" />
                        
                        
                        <p>商品分类： <select style="width:120px" id="setChange" name="cate1_id">
                        <?php if($cate){foreach($cate AS $val){?>
                        <option value="<?=$val['cate_id']?>" <?=$val['cate_id'] == $getData['cate1_id'] ? 'selected="selected"' : ''?>><?=$val['cate_name']?></option>
                        <?php }}else{?>
                        <option>没有数据</option>
                        <?php }?>
                        </select>&nbsp;<select style="width:120px" id="applyIn" name="cate2_id"></select>
                        &nbsp;
                            &nbsp;库存：<input type="text" style="width: 80px;" value="{{$getData.kcun}}" placeholder="库存" name="kcun" class="kcun" readonly />&nbsp;&nbsp;在线状态：<label style="display: inline"><input type="radio" name="status" style="margin-top: 1px" value="0" checked />下线&nbsp;&nbsp;</label><label style="display: inline"><input type="radio" name="status" style="margin-top: 1px" value="1" />上线</label>
                        </p>
                        <p><div id="setImd" style="display:inline">商品图片：<input type="text" placeholder="商品图片" name="goods_pic" class="setImdText" style="width:416px" value="<?=$getData['goods_pic']?>" readonly> <input type="button" class="btn btn-info setImdBtn" style='margin-top:-8px' value="选择图片">&nbsp;<a class="btn btn-warning  picViews" <?=$getData['goods_pic'] ? '' : 'disabled title="暂不可用"'?> url="<?=$getData['goods_pic'] ? transUrl($getData['goods_pic']) : ''?>" style='margin-top:-8px'>查看</a></div></p>
                        <p><div id="setImd1" style="display:inline">商品图二：<input type="text" placeholder="商品图片" name="goods_pic2" class="setImd1Text" style="width:416px" value="<?=$getData['goods_pic2']?>" readonly> <input type="button" class="btn btn-info setImd1Btn" style='margin-top:-8px' value="选择图片">&nbsp;<a class="btn btn-warning  picViews" <?=$getData['goods_pic2'] ? '' : 'disabled title="暂不可用"'?> url="<?=$getData['goods_pic2'] ? transUrl($getData['goods_pic2']) : ''?>" style='margin-top:-8px'>查看</a></div></p>
                        <p><div id="setImd2" style="display:inline">商品图三：<input type="text" placeholder="商品图片" name="goods_pic3" class="setImd2Text" style="width:416px" value="<?=$getData['goods_pic3']?>" readonly> <input type="button" class="btn btn-info setImd2Btn" style='margin-top:-8px' value="选择图片">&nbsp;<a class="btn btn-warning  picViews" <?=$getData['goods_pic3'] ? '' : 'disabled title="暂不可用"'?> url="<?=$getData['goods_pic3'] ? transUrl($getData['goods_pic3']) : ''?>" style='margin-top:-8px'>查看</a></div></p>

                        <p>店长返利：<input type="text" value="" placeholder="店长返利" style="width:60px" name="hjprofit" class="hjfl" type='text'> 元&nbsp;&nbsp;&nbsp;
                            经理返利：<input type="text" value="" placeholder="经理返利" style="width:60px" name="byprofit" class="byfl" type='text' readonly> 元&nbsp;&nbsp;&nbsp;
                            总监返利：<input type="text" value="" placeholder="总监返利" style="width:60px" name="zsprofit" class="zsfl" type='text' readonly > 元
                            &nbsp;&nbsp;排序：<input type="text" value="<?=$getData['sort']?>" style="width: 60px" placeholder="排序" name="sort" />
                        </p>

                        <p><textarea style="width:613px;height:310px;margin-left:73px;margin-top:-20px" name="content"><?=htmlspecialchars_decode($getData['goods_detail'])?></textarea></p>
                        <input type="hidden" value="{{$getData.id}}" name="goods_id" />
                        <input type="hidden" value="1" name="dosubmit" />
                    </form>
                </div>
                <div class="btn-toolbar">
                    <button class="btn btn-primary" id="btn-save" style="margin:18px 0 0 70px"><i class="icon-save"></i> 保存入库</button>
                    <div class="btn-group">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        //计算返利
        $('.goods_hb_price').bind('input onpropertychange',function(){
          //  $('.refer_price').val(($(this).val()/0.7).toFixed(0));
            $.get('/goods/gprice',{'price':$(this).val()},function(data){
            	doPlus();
                $('.hjfl').val(data.price1);
                $('.byfl').val(data.price2);
                $('.zsfl').val(data.price3);
            },'json');
        }).blur(function(){
            if($(this).val() == ''  || $(this).val() == 0){
                $('.hjfl').val('');
                $('.byfl').val('');
                $('.zsfl').val('');
            }
        });
/*         $.get('/goods/gprice',{'price':$('.goods_hb_price').val()},function(data){
        	doPlus();
            $('.hjfl').val(data.price1);
            $('.byfl').val(data.price2);
            $('.zsfl').val(data.price3);
        },'json'); */
        $('#plrate,#taxesId').change(function(){
        	if($('.goods_hb_price').val() > 0){
        		doPlus();
        	}else{
        		$('.goods_price,.refer_price').val('');
        	}
        });
        function doPlus(){
        	if($('.goods_hb_price').val() > 0 && $('#plrate').val() > -1){
        		$('#plusIng').show();
	        	$.post('/goods/skplus',{'price':$('.goods_hb_price').val(),'lm':$('#plrate').val(),'taxes':$('#taxesId').val()},function(data){
	        		$('#plusIng').hide();
	    			$('#goods_full_price').val(data.data.goods_full_price);
	    			$('.goods_price').val(data.data.goods_price);
	    			$('.goods_taxes_price').val(data.data.goods_taxes_price);
	    			$('#rates').val(data.data.rates);
	    		},'json');
        	}
        }
        /* $('.refer_price').bind('input onpropertychange',function(){
         //   $('.goods_price').val(($(this).val()*0.7).toFixed(0));
            $.get('/goods/gprice',{'price':$('.goods_price').val()},function(data){
                $('.hjfl').val(data.price1);
                $('.byfl').val(data.price2);
                $('.zsfl').val(data.price3);
            },'json'); */
       /*  }).blur(function(){
            if($(this).val() == ''  || $(this).val() == 0){
                $('.hjfl').val('');
                $('.byfl').val('');
                $('.zsfl').val('');
            }
        }); */

        $('#btn-save').click(function(){
            if(!($('.goods_title').val())){
                showmsg('商品名称不能为空');
                return false;
            }else if(!($('.goods_hb_price').val())){
                showmsg('销售现价不能为空');
                return false;
            }else if($('#plrate').val() < 0 ){
                showmsg('折扣品类必须选择');
                return false;
            }else if(!($('.goods_price').val())){
                showmsg('销售价格不能为空');
                return false;
            }else if(!($('.goods_taxes_price').val())){
                showmsg('扣税金额不能为空');
                return false;
            }else if(!($('.refer_price').val())){
                showmsg('参考价格不能为空');
                return false;
            }else if(!($('.goods_attr').val())){
                showmsg('产品规格不能为空');
                return false;
            }else if(!$('.kcun').val()) {
                showmsg('库存不能为空');
                return false;
            }else if(!$('.hjfl').val()){
                showmsg('黄金返利不能为空');
                return false;
            }else{
                setBtn($('#btn-save'));
                $('#formid').submit();
            }
        });
        $('.picViews').click(function(){
            var url = $(this).parent().find('a').attr('url');
            if(url != ''){
                showimg(url);
            }
        });
        $('.setImdBtn').click(function(){
            $('#setImd').selfups();
        });
        $('.setImd1Btn').click(function(){
            $('#setImd1').selfups();
        });
        $('.setImd2Btn').click(function(){
            $('#setImd2').selfups();
        });
//        $('.hjfl').blur(function(){
//            if(isNaN($('.hjfl').val())){
//                $('.hjfl').val('');
//            }else{
//                $.get('/goods/gprice',{'price':$('#ylz').val()},function(data){
//                    $('.byfl').val(data.price2);$('.zsfl').val(data.price3);
//                },'json');
//                mPrice = $('#ylz').val();
//            }
//        });
//        mPrice = $('.goods_price').val() - $('.channel_price').val();
//        setInterval(function checkNum(){
//            $('#ylz').val(($('.goods_price').val() - $('.channel_price').val()).toFixed(2));
//            if(mPrice - $('#ylz').val() > 0 || $('#ylz').val() - mPrice > 0){
//                console.log($('#ylz').val());
//                $.get('/goods/gprice',{'price':$('#ylz').val()},function(data){
//                    $('.byfl').val(data.price2);
//                    $('.hjfl').val(data.price1);
//                    $('.zsfl').val(data.price3);
//                },'json');
//                mPrice = $('#ylz').val();
//            }
//        },100);
        $('#setChange').change(function(){
            optionHtml = '';
            $.get('/goods/cates',{'ajaxFrom':'1','cateid':$(this).val()},function(data){
                if(data.length){
                    for(var i=0;i<data.length;i++){
                        optionHtml += '<option value='+data[i].cate_id+'>'+data[i].cate_name+'</option>';
                    }
                }else{
                    optionHtml = '<option value="0">没有行业数据</option>';

                }
                $('#applyIn').html(optionHtml);
            },'json');
        }).trigger('change');
    });
</script>